package leetcode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0704.java
 * @Author : WangRuoyu
 * @Date 2023/11/5 22:53
 */


public class Q0704 {
    public int search(int[] nums, int target) {
        int l = 0;
        int r = nums.length - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] >= target) r = mid;
            else l = mid + 1;
        }
        return nums[l] == target ? l : -1;
    }

    public static void main(String[] args) {
        Q0704 sl = new Q0704();
        int[] nums = {-1, 0, 3, 5, 9, 12};
        int target = 9;
        System.out.println(sl.search(nums, target));
    }
}